# Disk-Code-Makefile
#------------------------------------------------------------------------------
#******************************************************************************
#------------------------------------------------------------------------------
# Compiler
#------------------------------------------------------------------------------

FC=ifort
FLAGS =

#------------------------------------------------------------------------------
# Paths:
#------------------------------------------------------------------------------

code_path   = ./code/
mater_path  = ../mater/
common_path = ../common-code/
build_path  = ./build/

#------------------------------------------------------------------------------
# Input files:
#------------------------------------------------------------------------------

# Disk-Code - spezifische module

 CODEMOD    =  $(code_path)module.f90


# common code module

 COMMONMOD  =  $(common_path)common-module.f90


# common code

#COMMON +=  $(common_path)donorcell.f90
 COMMON  =  $(common_path)vanLeer.f90
#COMMON +=  $(common_path)superbee.f90

#COMMON +=  $(common_path)1Dsolver-fast.f90
#COMMON +=  $(common_path)1Dsolver-veryfast.f90
#COMMON +=  $(common_path)1Dsolver.f90
 COMMON +=  $(common_path)1Dsolver-talkative.f90
#COMMON +=  $(common_path)1Dsolver-andersrum.f90

 COMMON +=  $(common_path)time.f90
 COMMON +=  $(common_path)sim.f90
 COMMON +=  $(common_path)calc_error.f90
 COMMON +=  $(common_path)newton.f90


# Disk - spezifischer Code

 CODE +=  $(code_path)zint.f90
#CODE +=  $(code_path)matfct.f90
#CODE +=  $(code_path)matfct_ideal.f90
 CODE +=  $(code_path)matfct_ideal_opa1.f90
 CODE +=  $(code_path)eddfct.f90
 CODE +=  $(code_path)geomet.f90
 CODE +=  $(code_path)visco.f90
 CODE +=  $(code_path)grid.f90
 CODE +=  $(code_path)advec.f90

 CODE +=  $(code_path)output.f90
 CODE +=  $(code_path)readdata.f90
 CODE +=  $(code_path)readpar.f90

 CODE +=  $(code_path)newton_helper.f90
 CODE +=  $(code_path)Xcheck.f90
 CODE +=  $(code_path)calc_Xnorm.f90
 CODE +=  $(code_path)calc_tau.f90

 CODE +=  $(code_path)getready.f90



# Gleichungssystem und Jacobimatrix

 CODE +=  $(code_path)G_grid.f90
 CODE +=  $(code_path)DG_grid.f90
 CODE +=  $(code_path)G_cont.f90
 CODE +=  $(code_path)DG_cont.f90
 CODE +=  $(code_path)G_ene.f90
 CODE +=  $(code_path)DG_ene.f90
 CODE +=  $(code_path)G_mot_r.f90
 CODE +=  $(code_path)DG_mot_r.f90
 CODE +=  $(code_path)G_mot_phi.f90
 CODE +=  $(code_path)DG_mot_phi.f90
 CODE +=  $(code_path)G_radene.f90
 CODE +=  $(code_path)DG_radene.f90
 CODE +=  $(code_path)G_radflx.f90
 CODE +=  $(code_path)DG_radflx.f90


# debugging

 CODE +=  $(code_path)write_iterdat.f90


#------------------------------------------------------------------------------
# Specifying source-files in their intended location in the build-folder:
#     stripping path (when necessary) & adding build path
# the modules have to be the first entries in 'SOURCE'

SOURCE =  $(CODEMOD:$(code_path)%=$(build_path)%)
SOURCE += $(COMMONMOD:$(common_path)%=$(build_path)%)
SOURCE += $(CODE:$(code_path)%=$(build_path)%)
SOURCE += $(COMMON:$(common_path)%=$(build_path)%)

#------------------------------------------------------------------------------
# Specifying object files:  just by exchanging the extensions from .f90 to .o

OBJECTS = $(SOURCE:%.f90=%.o)

#------------------------------------------------------------------------------
# Specifying libraries

LIBS  =  -L$(mater_path) -lmater     # constitutive relations
#  -Ldir   ..Instructs linker to search "dir" for libraries
#  -lname  ..Links with the libary indicated in "name"
#            Naming convention for libaries:  link: "name"
#                                             file: libname.a

#------------------------------------------------------------------------------
# Dependencies:

DEPEND = $(mater_path)libmater.a

#------------------------------------------------------------------------------
# Build program
#------------------------------------------------------------------------------
# Executable:

# ifort - Version
1DD-Code.xl: ./update $(DEPEND) $(OBJECTS) ./Makefile
	$(FC) -fintrinsic-modules-path $(build_path) -o $@ $(FLAGS) $(OBJECTS) $(LIBS)


# Compilation:

%.o:%.f90
	$(FC) -c -fintrinsic-modules-path $(build_path) $(FLAGS) -o $@ $<


# copying or updating source files in build-folder

update: $(CODE) $(COMMON) $(CODEMOD) $(COMMONMOD) ./Makefile
	cp -u $(CODE) $(build_path)
	cp -u $(COMMON) $(build_path)
	cp -u $(CODEMOD) $(build_path)
	cp -u $(COMMONMOD) $(build_path)
	touch ./update

#------------------------------------------------------------------------------
# Cleanup section:
#------------------------------------------------------------------------------
# after complete clean of the build-directory we set the timestamp of ./update to  01.01.2000 00:00  (YYMMDDhhmm)
# in order to trigger the update process on the next execution of make

clean:
	rm -vf *.xl *~
	cd $(build_path); rm -vf *~ *.o *.mod *.d *.xl

veryclean:
	rm -vf *.xl *~
	cd $(build_path); rm -vf *
	cd $(code_path); rm -vf *~
	touch -t 0001010000 ./update

#------------------------------------------------------------------------------
# End of Makefile
#------------------------------------------------------------------------------


